package com.erclab.xpresso.forms
{
	import mx.controls.DataGrid;
	import mx.collections.ArrayCollection;
	
	import com.erclab.xpresso.formelements.FormElement;
	
	public class FormManagerUtil
	{
		
		public static function fillFormFromDG(theDataGrid:DataGrid, 
												theElements:ArrayCollection):void{

			var theItem:Object = theDataGrid.selectedItem;
			fillFormFromObject(theItem, theElements);
		}
		
		public static function fillFormFromObject(theItem:Object,
													theElements:ArrayCollection):void{

			if (theItem != null) {
				for each (var element:FormElement in theElements){
					var theValue:String = theItem[element.getAttribute("destinationColumn")];
					element.setValue(theValue);
				}
			}														
		}
		
	}
}